package com.bjc.platform.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bjc.platform.model.CustomUserDetails;
import com.bjc.platform.service.AdmOrgService;
import com.bjc.platform.util.StaticMethod;

@Controller
@RequestMapping("/login")
public class LoginController extends BaseController {

	@Autowired
	private AdmOrgService admOrgService;

	@RequestMapping(value = "/switchCompany", method = RequestMethod.POST)
	@ResponseBody
	public Object switchCompany(@RequestParam("companyId") Long companyId) {
		CustomUserDetails user = StaticMethod.getUser();
		String orgCode = null;
		if (companyId != null) {
			user.setOperCompany(admOrgService.get(companyId));
		}
        String code = StaticMethod.getOperationCompany().getCode();
        return StaticMethod.TOJSONResult(true, code).getJSONResult();
	}
}
